package 链表和树.二叉树;

import javax.swing.tree.TreeNode;

//Java：相同的树
public class SameTree{
    public static void main(String[] args) {
        Solution solution = new SameTree().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
//    public class TreeNode {
//        int val;
//        TreeNode left;
//        TreeNode right;
//        TreeNode() {}
//        TreeNode(int val) { this.val = val; }
//        TreeNode(int val, TreeNode left, TreeNode right) {
//            this.val = val;
//            this.left = left;
//            this.right = right;
//        }
//    }
class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p == null || q == null){
            return p == q ; //如果有一个不为null那么就说明不等
        }
        return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        //p.val == q.val只是判断头节点是否等后面不会执行了
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}